import os
from fastapi import UploadFile, File
from mian import RESOURCES
from mian.model.globalModel.globalModel import GlobalResponse


class Public:
    """
    公共方法类
    """

    async def saveFile(self, file: UploadFile = File(...)):
        """
        文件保存
        :param file: 文件
        :return: GlobalResponse 对象
        """
        fileName = file.filename
        savePath = os.path.join(RESOURCES, fileName)
        fileContent = await file.read()
        with open(savePath, 'wb') as f:
            f.write(fileContent)
        response = GlobalResponse()
        return response
